package org.cometmi.gwt.comet.client;

import org.cometmi.gwt.client.impl.WrapperFactoryClient;
import org.cometmi.gwt.shared.util.WrapperFactory;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextBox;

public class CometTest implements EntryPoint
{
	WrapperFactory wrapperFactory = GWT.create(WrapperFactoryClient.class);

	TestAsyncServiceAsync service = GWT.create(TestAsyncService.class);

	/**
	 * This is the entry point method.
	 */
	public void onModuleLoad()
	{
		final TextBox echoBox = new TextBox();

		Button sendButton = new Button("Send", new ClickHandler()
		{
			@Override
			public void onClick(ClickEvent event)
			{
				service.asyncEcho(echoBox.getValue(), new AsyncCallback<String>()
				{
					@Override
					public void onSuccess(String result)
					{
						Window.alert(result);
					}

					@Override
					public void onFailure(Throwable caught)
					{
						GWT.log("", caught);
						Window.alert("wooooops");
					}
				});
			}
		});

		RootPanel.get().add(echoBox);
		RootPanel.get().add(sendButton);
	}
}
